package edu.gatech.oad.antlab.person;

/**
 * MyFormater
 *
 * Version 1.0
 * @author jingyin zhang
 */

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;


/**
 * @author From an Example at exampledepot.com
 *
 */
public class MyFormater extends Formatter {
    // This method is called for every log records
    public String format(LogRecord rec) {
        StringBuffer buf = new StringBuffer(1000);
        // Bold any levels >= WARNING
        if (rec.getLevel().intValue() >= Level.WARNING.intValue()) {
            buf.append("<b>");
            buf.append(rec.getLevel());
            buf.append("</b>");
        } else {
            buf.append(rec.getLevel());
        }
        buf.append(' ');
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
        buf.append(formatter.format(rec.getMillis()));
        buf.append(' ');
        buf.append(formatMessage(rec));
        buf.append('\n');
        return buf.toString();
    }

    /**
     * This method is called just after the handler using this
     * formatter is created
     * 
     * @param handler
     * @return string of message
     */
    public String getHead(Handler h) {
        return "------Log time : "+(new Date())+"----\n";
    }
    /**
     *  This method is called just after the handler using this
     *  formatter is closed
     *  @param handler
     *  @return string of message
     */
    public String getTail(Handler h) {
        return "------------End-----------------";
    }
}

